const xStr =
  '王李张刘陈杨黄赵吴周徐孙马朱胡郭何林罗高郑梁谢宋唐许韩邓冯曹彭曾肖田董潘袁蔡蒋余于杜叶程魏苏吕丁任卢姚沈钟姜崔谭陆范汪廖石金韦贾夏付方邹熊白孟秦邱侯江尹薛月段雷龙黎史陶贺毛郝顾龚邵万覃武钱戴严莫孔向常黃洪赖庄萧简锺游詹施颜柯翁傅丁卓阮温蓝古纪连欧汤康尤巫涂童柳凃'
const xStr2 = [
  '欧阳',
  '上官',
  '皇甫',
  '令狐',
  '诸葛',
  '司徒',
  '司马',
  '申屠',
  '夏侯',
  '贺兰',
  '完颜',
  '慕容',
  '尉迟',
  '长孙'
]
const femaleStr = '嘉琼桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑婕馨瑗琰韵融园艺咏卿聪澜纯毓悦昭冰爽琬茗羽希宁欣飘育滢馥筠柔竹霭凝晓欢霄枫芸菲寒伊亚宜可姬舒影荔枝思丽秀娟英华慧巧美娜静淑惠珠翠雅芝玉萍红娥玲芬芳燕彩春菊勤珍贞莉兰凤洁梅琳素云莲真环雪荣爱妹霞香月莺媛艳瑞凡佳';
const maleStr = '涛昌进林有坚和彪博诚先敬震振壮会群豪心邦承乐绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾伟刚勇毅俊峰强军平保东文辉力明永健世广志义兴良海山仁波宁贵福生龙元全国胜学祥才发成康星光天达安岩中茂武新利清飞彬富顺信子杰楠榕风航弘';

const allNameStr = femaleStr + maleStr;

const xStrLength = xStr.length;
const femaleStrLength = femaleStr.length;
const maleStrLength = maleStr.length;
const allNameStrLength = allNameStr.length;


export function randomNum (min, max) {
  if (max - min >= 1) {
    const diff = max - min;
    return Math.floor(Math.random() * diff) + min;
  }
  return 'min必须小于max';
}
/**
 * 随机生成用户姓名
 * @return 返回随机生成的用户姓名
 */
 export function randomUserName (sex) {
  const ran = randomNum(0, 10);
  let mingStr = '';
  if (ran < 1) {
    // 姓名为2个字
    if (sex === 'male') {
      mingStr = maleStr[randomNum(0, maleStrLength)];
    } else if (sex === 'female') {
      mingStr = femaleStr[randomNum(0, femaleStrLength)];
    } else {
      mingStr = allNameStr[randomNum(0, allNameStrLength)];
    }
  } else {
    if (sex === 'male') {
      mingStr = maleStr[randomNum(0, maleStrLength)] + maleStr[randomNum(0, maleStrLength)];
    } else if (sex === 'female') {
      mingStr = femaleStr[randomNum(0, femaleStrLength)] + femaleStr[randomNum(0, femaleStrLength)];
    } else {
      mingStr = allNameStr[randomNum(0, allNameStrLength)] + allNameStr[randomNum(0, allNameStrLength)];
    }

  }
  return xStr[randomNum(0, xStrLength)] + mingStr;

}

export function randomFullRoomNum(){
  return randomNum(1, 16) + '号楼' + randomNum(1, 4) + '单元' + randomNum(1, 28) + '0' + randomNum(1, 4) + '号';
}

function getRoomUnit () {
  const num = randomNum(0, 3);
  let tempStr = '';
  if (num === 0) {
    tempStr = '号';
  } else if (num === 1) {
    tempStr = '室';
  } else if (num === 2) {
    tempStr = '';
  }
  return tempStr;
}
export function randomUnitNum (buildNumList) {
  
  let address = ''

  // 生成楼号
  let rBannerUnitNum = randomNum(0, 3);
  let bannerUnit = '栋';
  if(rBannerUnitNum === 0){
    bannerUnit = '号楼'
  }else if (rBannerUnitNum === 1){
    bannerUnit = '栋'
  }else {
    bannerUnit = '幢'
  }
  const bannerNum = buildNumList.length >0 ? buildNumList[randomNum(0, buildNumList.length)] : randomNum(1, 16);
  address+= bannerNum + bannerUnit;

  // 单元号
  let rDanYuanNum = randomNum(0,2)
  if(rDanYuanNum === 0){
    address += randomNum(1, 4) + '单元'
  }

  // 户号
  address += randomNum(1, 20) + '0' + randomNum(1, 4) + getRoomUnit()

  return address
}


export function replaceNumToHanNum(numStr){
  return numStr.replace(/[0-9]/g, function(match) {
    const numberToChineseMap = {
        '0': '零',
        '1': '一',
        '2': '二',
        '3': '三',
        '4': '四',
        '5': '五',
        '6': '六',
        '7': '七',
        '8': '八',
        '9': '九'
    };
    return numberToChineseMap[match];
  });
}
export function replaceHanNumToNum(str){
  return str.replace(/[零一二三四五六七八九]/g, function(match) {
    const chineseToNumberMap = {
        '零': '0',
        '一': '1',
        '二': '2',
        '三': '3',
        '四': '4',
        '五': '5',
        '六': '6',
        '七': '7',
        '八': '8',
        '九': '9'
    };
    return chineseToNumberMap[match];
  })
}